/*
 * @(#)CodingStyleExample.java 1.0 98/01/23 Achut Reddy
 *
 * Copyright (c) 1994-1998 Sun Microsystems, Inc. All Rights Reserved.
 */
package com.sun.examples;

import java.applet.Applet;
import java.awt.Point;

/**
 * A class to demonstrate good coding style.
 */
public class CodingStyleExample extends Applet implements Runnable {
	static final int BUFFER_SIZE = 4096; // default buffer size
	StringBuffer name; // my name
	Point starshipCoordinates[]; // ship locations

	/**
	 * Compute the total distance between a set of Points.
	 * 
	 * @param starshipCoordinates
	 *            the locations of all known starships
	 * @param numberOfPoints
	 *            the number of points in the array
	 * @return the total distance
	 */
	public int computeDistances(Point starshipCoordinates[], int numberOfPoints)
			throws Exception {
		int distance = 0; // accumulates distances
		// Compute distance to each starship and add it to the total
		for (int i = 0; i < numberOfPoints; i++) {
			distance += Math
					.sqrt((double) ((starshipCoordinates[i].x * starshipCoordinates[i].x) + (starshipCoordinates[i].y * starshipCoordinates[i].y)));
		}
		if (distance > 100000) {
			throw new Exception();
		}
		return distance;
	}

	/**
	 * Called whenever Thread.start() is called for this class
	 */
	public void run() {
		try {
			name.append("X");
			System.out.println(name); // NOPMD by Admin on 12-8-11 ����2:55
		} catch (Exception e) {
			name = new StringBuffer(BUFFER_SIZE);
		}
	}
}